        package DAL;

        import java.util.*;
        
        import DBUtil.SQLUtil;
        
        public class User {

		//获取用户表信息列表
		public List<Object> getEntity()
		{
			String sqlCmd="select *from User";
			return DBUtil.SQLUtil.executeQuery(sqlCmd, null);//执行查询操作executeQuery
		}
            
               //获取分页后用户表信息列表
		public List<Object> getEntity(int page)
		{
			int size=(page-1)*15;
			String sqlCmd="select *from V_User limit "+size+",15";
			return DBUtil.SQLUtil.executeQuery(sqlCmd, null);//执行查询操作executeQuery
		}
                
               //根据查询条件sqlWhere获取分页后用户表信息列表
		public List<Object> getEntityByWhere(String sqlWhere,int page)
		{
			int size=(page-1)*15;
			String sqlCmd="select *from V_User where "+sqlWhere+" limit "+ size+",15";
			return DBUtil.SQLUtil.executeQuery(sqlCmd, null);//执行查询操作executeQuery
        }
        
        //删除用户表信息
        public int deleteEntity(String UserId)
        {
            String sqlCmd="delete from User where UserId='"+UserId+"'";
            return DBUtil.SQLUtil.executeNonQuery(sqlCmd, null);//执行非查询操作executeNonQuery
        }
        
        //根据用户表编号获取用户表信息
        public List<Object> getEntityById(String UserId)
        {
            String sqlCmd="select *From V_User where UserId='"+UserId+"'";
            return DBUtil.SQLUtil.executeQuery(sqlCmd, null);//执行查询操作executeQuery
        }
        
        //更新用户表信息
        public int updateEntity(String UserId,String RoleId,String UserName,String RealName,String UserPwd,String UserPhone)
        {
            String sqlCmd="Update User set RoleId='" + RoleId + "',UserName='" + UserName + "',RealName='" + RealName + "',UserPwd='" + UserPwd + "',UserPhone='" + UserPhone + "' where UserId='"+UserId+"'";
            return SQLUtil.executeNonQuery(sqlCmd, null);
        }
        
        //插入用户表信息
        public int insertEntity(String UserId,String RoleId,String UserName,String RealName,String UserPwd,String UserPhone)
        {
            String sqlCmd="Insert into User values('" + UserId + "','" + RoleId + "','" + UserName + "','" + RealName + "','" + UserPwd + "','"+UserPhone+"')";
            return SQLUtil.executeNonQuery(sqlCmd, null);
        }
        
        //检查插入主键是否重复
        public boolean checkExist(String UserId)
        {
            String sqlCmd="select count(*) from User where UserId='"+UserId+"'";
            if(1==Integer.parseInt(SQLUtil.excuteScalar(sqlCmd, null).toString()) )
            {
                return true;
            }
            return false;
        }

        //检查插入密码是否输入正确（改密码）
        public boolean checkPwd(String UserId,String pwd)
        {
            String sqlCmd="select count(*) from User where UserId='"+UserId+"' and UserPwd='"+pwd+"'";
            if(1==Integer.parseInt(SQLUtil.excuteScalar(sqlCmd, null).toString()) )
            {
                return true;
            }
            return false;
        }
        
        //检查插入密码是否输入正确（改密码）
        public boolean updataPwd(String UserId,String pwd)
        {
            String sqlCmd="Update user set userPwd='"+pwd+"'  where UserId='"+UserId+"'";
            if(SQLUtil.executeNonQuery(sqlCmd, null)==1)
            {
            	return true;
            }
            return false;
        }
        
		//获取分页总数
		public Object getPageCount()
		{
			String sqlCmd="SELECT CEIL( COUNT(*)/15.0) FROM V_User ";
			return SQLUtil.excuteScalar(sqlCmd, null);
		}

		//根据查询条件获取分页总数
		public Object getPageCountByWhere(String sqlWhere)
		{
			String sqlCmd="SELECT CEIL( COUNT(*)/15.0) FROM V_User where "+sqlWhere;
			return SQLUtil.excuteScalar(sqlCmd, null);
		}
            
        }
